#include "conf.h"

void change_video_tables(int a, int b){
}


void  set_quality(int *x){ // -17 highest; +12 lowest
 if (conf.video_mode) *x=12-((conf.video_quality-1)*(12+17)/(99-1));
}


void __attribute__((naked,noinline)) movie_record_task(){ 
 asm volatile(
                 "STMFD   SP!, {R2-R8,LR}\n"
                 "LDR     R8, =0x442\n"
                 "LDR     R7, =0x2710\n"
                 "LDR     R4, =0x6588\n"
                 "MOV     R6, #0\n"
                 "MOV     R5, #1\n"
"loc_FF9382D0:\n"
                 "LDR     R0, [R4,#0x18]\n"
                 "MOV     R2, #0\n"
                 "ADD     R1, SP, #0x4\n"
                 "BL      sub_FF826D3C\n"
                 "LDR     R0, [R4,#0x20]\n"
                 "CMP     R0, #0\n"
                 "BNE     loc_FF9383A0\n"
                 "LDR     R0, [SP,#0x4]\n"
                 "LDR     R1, [R0]\n"
                 "SUB     R1, R1, #2\n"
                 "CMP     R1, #9\n"
                 "ADDLS   PC, PC, R1,LSL#2\n"
                 "B       loc_FF9383A0\n"
"loc_FF938304:\n"
                 "B       loc_FF938354\n"
"loc_FF938308:\n"
                 "B       loc_FF938374\n"
"loc_FF93830C:\n"
                 "B       loc_FF938384\n"
"loc_FF938310:\n"
                 "B       loc_FF93838C\n"
"loc_FF938314:\n"
                 "B       loc_FF93835C\n"
"loc_FF938318:\n"
                 "B       loc_FF938394\n"
"loc_FF93831C:\n"
                 "B       loc_FF938364\n"
"loc_FF938320:\n"
                 "B       loc_FF9383A0\n"
"loc_FF938324:\n"
                 "B       loc_FF93839C\n"
"loc_FF938328:\n"
                 "B       loc_FF93832C\n"
"loc_FF93832C:\n"
                 "LDR     R0, =0xFF937FCC\n"
                 "STR     R6, [R4,#0x34]\n"
                 "STR     R0, [R4,#0x9C]\n"
                 "LDR     R0, =0xFF9375EC\n"
                 "LDR     R2, =0xFF937508\n"
                 "LDR     R1, =0x4C6D8\n"
                 "STR     R6, [R4,#0x24]\n"
                 "BL      sub_FF838FE4\n"
                 "STR     R5, [R4,#0x38]\n"
                 "B       loc_FF9383A0\n"
"loc_FF938354:\n"
                 "BL      unlock_optical_zoom\n" 		//  -----------> inserted to unlock the zoom
                 "BL      sub_FF9380D4\n"
                 "B       loc_FF9383A0\n"
"loc_FF93835C:\n"
                 "BL      sub_FF937C70_my\n"               //----------------->
                 "B       loc_FF9383A0\n"
"loc_FF938364:\n"
                 "LDR     R1, [R0,#0x18]\n"
                 "LDR     R0, [R0,#4]\n"
                 "BL      sub_FFA63230\n"
                 "B       loc_FF9383A0\n"
"loc_FF938374:\n"
                 "LDR     R0, [R4,#0x38]\n"
                 "CMP     R0, #5\n"
                 "STRNE   R5, [R4,#0x28]\n"
                 "B       loc_FF9383A0\n"
"loc_FF938384:\n"
                 "BL      sub_FF937958\n"
                 "B       loc_FF9383A0\n"
"loc_FF93838C:\n"
                 "BL      sub_FF937638\n"
                 "B       loc_FF9383A0\n"
"loc_FF938394:\n"
                 "BL      sub_FF937494\n"
                 "B       loc_FF9383A0\n"
"loc_FF93839C:\n"
                 "BL      sub_FF938508\n"
"loc_FF9383A0:\n"
                 "LDR     R1, [SP,#0x4]\n"
                 "LDR     R3, =0xFF9372F8\n"
                 "STR     R6, [R1]\n"
                 "STR     R8, [SP]\n"
                 "LDR     R0, [R4,#0x1C]\n"
                 "MOV     R2, R7\n"
                 "BL      sub_FF827690\n"
                 "B       loc_FF9382D0\n"
 );
}

void __attribute__((naked,noinline)) sub_FF937C70_my(){ 
 asm volatile(
                 "STMFD   SP!, {R4-R9,LR}\n"
                 "SUB     SP, SP, #0x44\n"
                 "MOV     R7, #0\n"
                 "LDR     R6, =0x6588\n"
                 "MOV     R4, R0\n"
                 "STR     R7, [SP,#0x34]\n"
                 "STR     R7, [SP,#0x2C]\n"
                 "LDR     R0, [R6,#0x38]\n"
                 "MOV     R8, #4\n"
                 "CMP     R0, #3\n"
                 "STREQ   R8, [R6,#0x38]\n"
                 "LDR     R0, [R6,#0x9C]\n"
		     "BLX 	  R0\n"
                 "LDR     R0, [R6,#0x38]\n"
                 "CMP     R0, #4\n"
                 "BNE     loc_FF937DC0\n"
                 "ADD     R3, SP, #0x2C\n"
                 "ADD     R2, SP, #0x30\n"
                 "ADD     R1, SP, #0x34\n"
                 "ADD     R0, SP, #0x38\n"
                 "BL      sub_FFA632CC\n"
                 "CMP     R0, #0\n"
                 "MOV     R5, #1\n"
                 "BNE     loc_FF937CEC\n"
                 "LDR     R1, [R6,#0x28]\n"
                 "CMP     R1, #1\n"
                 "BNE     loc_FF937DD4\n"
                 "LDR     R1, [R6,#0x4C]\n"
                 "LDR     R2, [R6,#0x3C]\n"
                 "CMP     R1, R2\n"
                 "BCC     loc_FF937DD4\n"
"loc_FF937CEC:\n"
                 "CMP     R0, #0x80000001\n"
                 "STREQ   R8, [R6,#0x50]\n"
                 "BEQ     loc_FF937D24\n"
                 "CMP     R0, #0x80000003\n"
                 "STREQ   R5, [R6,#0x50]\n"
                 "BEQ     loc_FF937D24\n"
                 "CMP     R0, #0x80000005\n"
                 "MOVEQ   R0, #2\n"
                 "BEQ     loc_FF937D20\n"
                 "CMP     R0, #0x80000007\n"
                 "STRNE   R7, [R6,#0x50]\n"
                 "BNE     loc_FF937D24\n"
                 "MOV     R0, #3\n"
"loc_FF937D20:\n"
                 "STR     R0, [R6,#0x50]\n"
"loc_FF937D24:\n"
                 "LDR     R0, =0x4C70C\n"
                 "LDR     R0, [R0,#8]\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF937D3C\n"
                 "BL      sub_FF84A188\n"
                 "B       loc_FF937D40\n"
"loc_FF937D3C:\n"
                 "BL      sub_FF937494\n"
"loc_FF937D40:\n"
                 "LDR     R0, [R4,#0x1C]\n"
                 "LDR     R1, [R4,#0x20]\n"
                 "ADD     R3, SP, #0x3C\n"
                 "MVN     R2, #1\n"
                 "ADD     R7, SP, #0x18\n"
                 "STMIA   R7, {R0-R3}\n"
                 "LDR     R2, [R6,#0x64]\n"
                 "LDR     R3, [R6,#0x68]\n"
                 "MOV     R0, #0\n"
                 "ADD     R1, SP, #0x40\n"
                 "ADD     R7, SP, #0x8\n"
                 "STMIA   R7, {R0-R3}\n"
                 "MOV     R3, #0\n"
                 "MOV     R2, #0x40\n"
                 "STRD    R2, [SP]\n"
                 "LDMIB   R4, {R0,R1}\n"
                 "LDR     R3, =0x4C724\n"
                 "MOV     R2, R9\n"
                 "BL      sub_FFA23604\n"
                 "LDR     R0, [R6,#0x10]\n"
                 "MOV     R1, #0x3E8\n"
                 "BL      sub_FF827158\n"
                 "CMP     R0, #9\n"
                 "BEQ     loc_FF937E58\n"
                 "LDR     R0, [SP,#0x3C]\n"
                 "CMP     R0, #0\n"
                 "BNE     loc_FF937E74\n"
                 "MOV     R0, #1\n"
                 "BL      sub_FFA236AC\n"
                 "BL      sub_FFA236E8\n"
                 "MOV     R0, #5\n"
                 "STR     R0, [R6,#0x38]\n"
"loc_FF937DC0:\n"
                 "ADD     SP, SP, #0x44\n"
                 "LDMFD   SP!, {R4-R9,PC}\n"
"loc_FF937DC8:\n"
                 "BL      sub_FF87BF7C\n"
                 "MOV     R0, #1\n"
                 "B       loc_FF937F14\n"
"loc_FF937DD4:\n"
                 "LDR     R12, [SP,#0x34]\n"
                 "CMP     R12, #0\n"
                 "BEQ     loc_FF937F74\n"
                 "STR     R5, [R6,#0x2C]\n"
                 "LDR     R0, [R6,#0x4C]\n"
                 "LDR     R8, [R4,#0xC]\n"
                 "CMP     R0, #0\n"
                 "LDRNE   LR, [SP,#0x38]\n"
                 "BNE     loc_FF937EA0\n"
                 "LDR     R0, [R4,#0x1C]\n"
                 "LDR     R1, [R4,#0x20]\n"
                 "ADD     R3, SP, #0x3C\n"
                 "MVN     R2, #0\n"
                 "ADD     R9, SP, #0x18\n"
                 "STMIA   R9, {R0-R3}\n"
                 "LDR     R0, [SP,#0x2C]\n"
                 "LDR     R2, [R6,#0x64]\n"
                 "LDR     R3, [R6,#0x68]\n"
                 "ADD     R1, SP, #0x40\n"
                 "ADD     R9, SP, #0x8\n"
                 "STMIA   R9, {R0-R3}\n"
                 "LDR     R3, [SP,#0x30]\n"
                 "STR     R12, [SP]\n"
                 "STR     R3, [SP,#0x4]\n"
                 "LDMIB   R4, {R0,R1}\n"
                 "LDR     R3, [SP,#0x38]\n"
                 "MOV     R2, R8\n"
                 "BL      sub_FFA23604\n"
                 "LDR     R0, [R6,#0x10]\n"
                 "MOV     R1, #0x3E8\n"
                 "BL      sub_FF827158\n"
                 "CMP     R0, #9\n"
                 "BNE     loc_FF937E68\n"
"loc_FF937E58:\n"
                 "BL      sub_FFA63798\n"
                 "MOV     R0, #0x90000\n"
                 "STR     R5, [R6,#0x38]\n"
                 "B       loc_FF937DC8\n"
"loc_FF937E68:\n"
                 "LDR     R0, [SP,#0x3C]\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF937E84\n"
"loc_FF937E74:\n"
                 "BL      sub_FFA63798\n"
                 "MOV     R0, #0xA0000\n"
                 "STR     R5, [R6,#0x38]\n"
                 "B       loc_FF937DC8\n"
"loc_FF937E84:\n"
                 "MOV     R0, #1\n"
                 "BL      sub_FFA236AC\n"
                 "LDR     R0, [SP,#0x40]\n"
                 "LDR     R1, [SP,#0x38]\n"
                 "ADD     LR, R1, R0\n"
                 "LDR     R1, [SP,#0x34]\n"
                 "SUB     R12, R1, R0\n"
"loc_FF937EA0:\n"
                 "LDR     R0, [R4,#0x1C]\n"
                 "LDR     R2, [R6,#0x48]\n"
                 "LDR     R1, [R4,#0x20]\n"
                 "ADD     R3, SP, #0x3C\n"
                 "ADD     R9, SP, #0x18\n"
                 "STMIA   R9, {R0-R3}\n"
                 "LDR     R0, [SP,#0x2C]\n"
                 "LDR     R2, [R6,#0x64]\n"
                 "LDR     R3, [R6,#0x68]\n"
                 "ADD     R1, SP, #0x40\n"
                 "ADD     R9, SP, #0x8\n"
                 "STMIA   R9, {R0-R3}\n"
                 "LDR     R3, [SP,#0x30]\n"
                 "STR     R12, [SP]\n"
                 "STR     R3, [SP,#0x4]\n"
                 "LDMIB   R4, {R0,R1}\n"
                 "MOV     R3, LR\n"
                 "MOV     R2, R8\n"
                 "BL      sub_FFA23604\n"
                 "LDR     R0, [R6,#0x10]\n"
                 "MOV     R1, #0x3E8\n"
                 "BL      sub_FF827158\n"
                 "CMP     R0, #9\n"
                 "BNE     loc_FF937F1C\n"
                 "BL      sub_FFA63798\n"
                 "MOV     R0, #0x90000\n"
                 "STR     R5, [R6,#0x38]\n"
                 "BL      sub_FF87BF7C\n"
                 "MOV     R0, #0\n"
"loc_FF937F14:\n"
                 "BL      sub_FFA236AC\n"
                 "B       loc_FF937DC0\n"
"loc_FF937F1C:\n"
                 "LDR     R0, [SP,#0x3C]\n"
                 "CMP     R0, #0\n"
                 "BEQ     loc_FF937F3C\n"
                 "BL      sub_FFA63798\n"
                 "MOV     R0, #0xA0000\n"
                 "STR     R5, [R6,#0x38]\n"
                 "BL      sub_FF87BF7C\n"
                 "B       loc_FF937DC0\n"
"loc_FF937F3C:\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FFA236AC\n"

                 "LDR     R0, [SP,#0x38]\n"
                 "LDR     R1, [SP,#0x40]\n"
                 "BL      sub_FFA634F4\n"
                 "LDR     R0, [R6,#0x48]\n"
                 "LDR     R3, =0x65F0\n"        // ---> -
                 "ADD     R1, R0, #1\n"         //       |
                 "STR     R1, [R6,#0x48]\n"     //       |
                 "STR     R3, [SP]\n"           //       |
                 "LDR     R0, [SP,#0x40]\n"     //       |
                 "SUB     R3, R3, #4\n"         // ---> -
                 "MOV     R2, #0xF\n"           //       |
                 "BL      sub_FFA61698\n"       //       |
                                                //       |
                 "LDR     R0, =0x65F0-4\n"      // -<---     // +
                 "BL      set_quality\n"                     // +
"loc_FF937F74:\n"
                 "LDR     R0, [R6,#0x4C]\n"
                 "ADD     R0, R0, #1\n"
                 "STR     R0, [R6,#0x4C]\n"
                 "LDR     R1, [R6,#0x74]\n"
                 "MUL     R0, R1, R0\n"
                 "LDR     R1, [R6,#0x70]\n"
                 "BL      sub_FFAFB000\n"
                 "MOV     R4, R0\n"
                 "BL      sub_FFA637D0\n"
                 "LDR     R1, [R6,#0x6C]\n"
                 "CMP     R1, R4\n"
                 "BNE     loc_FF937FB0\n"
                 "LDR     R0, [R6,#0x30]\n"
                 "CMP     R0, #1\n"
                 "BNE     loc_FF937FC4\n"
"loc_FF937FB0:\n"
                 "LDR     R1, [R6,#0x80]\n"
                 "MOV     R0, R4\n"
		     "BLX 	  R1\n"
                 "STR     R4, [R6,#0x6C]\n"
                 "STR     R7, [R6,#0x30]\n"
"loc_FF937FC4:\n"
                 "STR     R7, [R6,#0x2C]\n"
                 "B       loc_FF937DC0\n"
 );
}
